﻿<UserControl x:Class="SSLVerifier.UserControls.CertTreeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:viewModels="clr-namespace:SSLVerifier.API.ViewModels"
             mc:Ignorable="d"
			 Background="{StaticResource PanelHeaderBackground}"
			 Foreground="Navy"
			 d:DataContext="{d:DesignInstance viewModels:MainWindowVM}">
	<UserControl.Resources>
		<Style x:Key="Img" TargetType="Image">
			<Setter Property="Source" Value="../Images/Misc/normalcert.png"/>
			<Style.Triggers>
				<DataTrigger Binding="{Binding Value.HasWarnings}" Value="True">
					<Setter Property="Source" Value="../Images/Misc/warncert.png"/>
				</DataTrigger>
				<DataTrigger Binding="{Binding Value.HasErrors}" Value="True">
					<Setter Property="Source" Value="../Images/Misc/failedcert.png"/>
				</DataTrigger>
				<DataTrigger Binding="{Binding Value.IsRoot}" Value="True">
					<Setter Property="Source" Value="../Images/Misc/certs_16x16.png"/>
				</DataTrigger>
			</Style.Triggers>
		</Style>
	</UserControl.Resources>
    <Grid>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="300"/>
			<ColumnDefinition Width="5"/>
			<ColumnDefinition Width="*"/>
		</Grid.ColumnDefinitions>
		<StackPanel Grid.Column="0" HorizontalAlignment="Left">
			<Button Content="View certificate" Command="{Binding ViewChainCertificateCommand}" Width="100"/>
		</StackPanel>
		<TreeView Name="tree"
				  Grid.Column="0"
				  SelectedItemChanged="TreeView_OnSelectedItemChanged"
				  MouseDoubleClick="TreeMouseDoubleClick"
				  ItemsSource="{Binding SelectedItem.Tree}"
				  ScrollViewer.CanContentScroll="True" Margin="0,25,0,0">
			<TreeView.ItemTemplate>
				<HierarchicalDataTemplate ItemsSource="{Binding Children}">
					<StackPanel Orientation="Horizontal">
						<Image Style="{StaticResource Img}" Height="16" Width="16"/>
						<TextBlock  HorizontalAlignment="Stretch" Margin="5,0" Text="{Binding Value.Name}" />
					</StackPanel>
				</HierarchicalDataTemplate>
			</TreeView.ItemTemplate>
			<TreeView.ItemContainerStyle>
				<Style TargetType="{x:Type TreeViewItem}">
					<Setter Property="IsExpanded" Value="True"/>
				</Style>
			</TreeView.ItemContainerStyle>
		</TreeView>
		<GridSplitter Grid.Column="1" Width="5" ResizeBehavior="PreviousAndNext" HorizontalAlignment="Center" VerticalAlignment="Stretch" ResizeDirection="Columns"/>
		<Grid Grid.Column="2">
			<Grid.RowDefinitions>
				<RowDefinition/>
				<RowDefinition/>
			</Grid.RowDefinitions>
			<TextBlock Grid.Row="0" Margin="5,0,0,0" Text="Propagated errors:"/>
			<TextBox Grid.Row="0"
					 IsUndoEnabled="False"
					 UndoLimit="0"
					 FontFamily="Consolas"
					 IsReadOnly="True"
					 IsReadOnlyCaretVisible="True"
					 ScrollViewer.CanContentScroll="True"
					 TextWrapping="Wrap"
					 VerticalScrollBarVisibility="Auto"
					 Margin="0,18,0,0"
					 HorizontalAlignment="Stretch"
					 VerticalAlignment="Stretch"
					 Foreground="Orange"
					 Text="{Binding SelectedTreeItem.PropagatedErrorString, Mode=OneWay}"/>
			<TextBlock Grid.Row="1" Margin="5,0,0,0" Text="Native errors:"/>
			<TextBox Grid.Row="1"
					 IsUndoEnabled="False"
					 UndoLimit="0"
					 FontFamily="Consolas"
					 IsReadOnly="True"
					 IsReadOnlyCaretVisible="True"
					 ScrollViewer.CanContentScroll="True"
					 TextWrapping="Wrap"
					 VerticalScrollBarVisibility="Auto"
					 Margin="0,18,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="Red" Text="{Binding SelectedTreeItem.NativeErrorString, Mode=OneWay}"/>
		</Grid>
	</Grid>
</UserControl>
